package com.hkfn.rfb.rfb.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hkfn.rfb.R;
import com.hkfn.rfb.common.activity.BaseActivity;
import com.hkfn.rfb.common.adapter.BaseRecyclerAdapter;

public class RfbTrendSummaryHeadAdapter extends BaseRecyclerAdapter<String> {

    private BaseActivity activity;

    private int currentIndex = 0;

    public int getCurrentIndex() {
        return currentIndex;
    }

    public void setCurrentIndex(int currentIndex) {
        this.currentIndex = currentIndex;
    }

    public RfbTrendSummaryHeadAdapter(BaseActivity activity) {
        this.activity = activity;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(activity).inflate(R.layout.item_rfb_trend_summary_head, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, String data) {
        if (viewHolder instanceof MyViewHolder){
            setItemData((MyViewHolder)viewHolder, data, RealPosition);
        }
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{

        private LinearLayout ll_item_content;

        private TextView tv_trend_summary_head;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            initItemView(this, itemView);
        }
    }

    private void initItemView(MyViewHolder myViewHolder, View itemView) {
        myViewHolder.ll_item_content = itemView.findViewById(R.id.ll_item_content);
        myViewHolder.tv_trend_summary_head = itemView.findViewById(R.id.tv_trend_summary_head);
    }

    private void setItemData(MyViewHolder viewHolder, String data, int position) {
        if (currentIndex == position){
            viewHolder.ll_item_content.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_trend_summary_head_select_frame));
        }else {
            viewHolder.ll_item_content.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_trend_summary_head_unselect_frame));
        }
        viewHolder.tv_trend_summary_head.setText(data);
    }
}
